var mongoose = require('mongoose');

function Comment(name, day, title, comment) {
    this.name = name;
    this.day = day;
    this.title = title;
    this.comment = comment;
}

var commentSchema = new mongoose.Schema({
    name: String,
    day: String,
    title: String,
    comments: [String]
},{
    collection: 'posts'
});

var commentModel = mongoose.model('Comment', commentSchema);

module.exports = Comment;

//存储一条留言信息
Comment.prototype.save = function (callback) {
    var name = this.name,
        day = this.day,
        title = this.title,
        comment = this.comment;

    commentModel.update({
        "name": name,
        "time.day": day,
        "title": title
    },{
        $push: {"comments": comment}
    }, function (err) {
        callback(err);
    })

};
